package org.fullhappy.dao;

import java.util.List;
import java.util.logging.Logger;

import javax.persistence.EntityManager;

import org.fullhappy.entity.Product;

public class ProductDAO extends DAO<Product> {
	public ProductDAO() {
		super(Product.class);
	}
	
	public List<Product> findByCategoryId(long categoryId) {
		EntityManager entityManager = EMF.get().createEntityManager();
		List<Product> list1 = null;
		try {
			List<Product> list = entityManager.createQuery(
					" SELECT e FROM " + Product.class.getSimpleName() + " e WHERE e.categoryId = " + categoryId)
					.getResultList();
			list1 = list.subList(0, list.size());
		} catch (Exception e) {
			Logger.getLogger("findByCategoryId" + e.getMessage());
		} finally {
			entityManager.close();
		}
		return list1;
	}

}
